<script lang="ts" setup>
import {mainAttraction, mainNews, mainRoute} from "../serve.ts"
import {ref} from "vue"
import {useRouter} from 'vue-router'
import {ArrowRightBold} from "@element-plus/icons-vue";

const
    router = useRouter(),
    routes = ref([]),
    rLo = ref(true),
    newsList = ref([]),
    nLo = ref(true),
    attractions = ref([])
;

function get() {
  mainRoute({page: 1, size: 8}).then((r: any) => {
    routes.value = r.list
    rLo.value = false
    // console.log(r.list)
  })
  mainNews({page: 1, size: 6}).then((r: any) => {
    newsList.value = r.list
    nLo.value = false
    // console.log(r.list)
  })
  mainAttraction({page: 1, size: 8}).then((r: any) => {
    attractions.value = r.list
    nLo.value = false
    // console.log(r.list)
  })
}

function openNewTab(id: any) {
  const r = router.resolve({path: '/information-details', query: {id}})
  window.open(r.href, '_blank')
}

function opNewTab(id: any, path: any) {
  const r = router.resolve({path, query: {id}})
  window.open(r.href, '_blank')
}

get()
const carouselImages = [
  '../轮播1.jpg',
  '../轮播2.jpg',
  '../轮播3.jpg',
  '../轮播4.jpg',
]
</script>

<template>
  <el-scrollbar>
    <el-carousel height="500px">
      <el-carousel-item v-for="item in carouselImages" :key="item">
        <el-image :src="item" style="width: 100%;display: block;height: 100%;"/>
      </el-carousel-item>
    </el-carousel>
    <div con class="container">
      <div v-loading="rLo" element-loading-text="加载中..." travel>
        <div tr-top>
          <div dis>
            <div>旅游路线</div>
            <div class="turnTo" @click="router.push('/routeTon').catch(()=>true)">
              <div>全部路线</div>
              <el-icon>
                <ArrowRightBold/>
              </el-icon>
            </div>
          </div>
        </div>
        <div class="route-list">
          <div @click="opNewTab(item['routeId'],'/routeTon-details')" v-for="(item, index) in routes" :key="index"
               :style="{ backgroundImage: `url(${item['pic']})` }"
               class="route-card">
            <div class="card-number">{{ index + 1 }}</div>
            <div class="card-content">
              <h3 class="ellipsis">{{ item['title'] }}</h3>
              <p class="ellipsis">{{ item['special'] }}</p>
            </div>
            <div class="card-mask"></div>
          </div>
        </div>
      </div>
      <!-- 分隔线 -->
      <div class="divider">
        <span class="divider-line"></span>
        <h1 class="divider-text">热门景点</h1>
        <span class="divider-line"></span>
      </div>
      <div style="width: 90%;margin: auto auto 80px;">
        <div class="attraction-list">
          <div @click="opNewTab(item['attractionId'],'/come-details')" v-for="(item, index) in attractions" :key="index"
               :style="{ backgroundImage: `url(${item['pic']})` }"
               class="attraction-item">
            <div class="attraction-title ellipsis">
              {{ item['name'] }}
            </div>
          </div>
        </div>
      </div>
      <!-- 分隔线 -->
      <div class="divider">
        <span class="divider-line"></span>
        <h1 class="divider-text">旅游资讯</h1>
        <span class="divider-line"></span>
      </div>
      <div v-loading="nLo" element-loading-text="加载中..." style="padding-bottom: 0;" travel>
        <div tr-top>
          <div dis>
            <div>旅游资讯</div>
            <div class="turnTo"
                 @click="router.push('/information').catch(()=>true)">
              <div>全部资讯</div>
              <el-icon>
                <ArrowRightBold/>
              </el-icon>
            </div>
          </div>
        </div>
        <div class="news-list">
          <div v-for="(news, index) in newsList" :key="index" class="news-item" @click="openNewTab(news['articleId'])">
            <div class="news-title">{{ news['title'] }}</div>
            <div class="news-date">{{ news['createdAt'] }}</div>
          </div>
        </div>
      </div>
      <div style="width: 98%;margin-top: 40px;height: 1px;background-color: #002B49;"/>
      <div class="copyright">© 2025 旅游网站</div>
    </div>
  </el-scrollbar>
</template>

<style lang="scss" scoped>
.turnTo {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.turnTo:hover {
  transform: scale(1.2);
  transition: transform 0s linear;
}

[con] {
  padding-top: 30px;
}

.ellipsis {
  white-space: nowrap; /* 禁止文本换行 */
  overflow: hidden; /* 隐藏超出容器的文本 */
  text-overflow: ellipsis; /* 使用省略号表示溢出的文本 */
}

.container {
  background-image: url('/bg.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: repeat-x;
}

[travel] {
  width: 90%;
  margin: auto;
  font-family: 'Microsoft YaHei', sans-serif;
  background-color: white;
  padding-bottom: 25px;
  border-radius: 6px;

  [tr-top] {
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    background-color: #0062A5;
    color: #FFFFFF;
    padding: 25px;

    [dis] {
      display: flex;
      justify-content: space-between;
      font-size: 24px;
      font-weight: bold;
      padding-left: 10px;
      border-left: 4px solid #1890ff;
      align-items: center;

      div:nth-child(2) {
        font-size: 16px;
        font-weight: 400;
      }
    }
  }

  .route-list {
    margin: 30px 0;
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 15px;
  }

  .route-card {
    width: 22%;
    height: 230px;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    background-size: cover;
    background-position: center;
    border-radius: 15px;
  }

  .route-card:hover {
    transform: scale(1.05);
    transition: transform 0.3s ease;
  }

  .card-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.6) 100%);
  }

  .news-list {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
  }

  .news-item {
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
  }

  .news-item:last-child {
    border-bottom: none;
  }

  .news-item:hover {
    background-color: #f0f0f0;
    transition: background-color 0.3s ease;
  }

  .news-date {
    color: #999;
    font-size: 15px;
    min-width: 90px;
  }

  .news-title {
    color: #333;
    font-size: 20px;
    margin-bottom: 10px;
  }
}

.divider {
  display: flex;
  align-items: center;
  margin: 50px 0 50px 0;
  justify-content: center;

  .divider-line {
    height: 3px;
    width: 100px;
    border-radius: 2px;
    background: #dcdfe6;
  }

  .divider-text {
    padding: 0 12px;
    //color: #8898aa;
    //font-size: 12px;
    color: #ffffff;
  }
}

.card-number {
  position: absolute;
  top: 12px;
  left: 12px;
  font-size: 28px;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.9);
  z-index: 1;
}

.card-content {
  position: absolute;
  bottom: 15%;
  left: 40%;
  font-size: 22px;
  right: 0;
  color: white;
  z-index: 1;
}

.card-content h3 {
  font-size: 18px;
  margin: 0 0 8px;
}

.card-content p {
  font-size: 12px;
  line-height: 1.4;
  opacity: 0.9;
  margin: 0;
}


.attraction-list {
  display: flex;
  justify-content: flex-start;
  border-radius: 8px;
  flex-wrap: wrap;
}

.attraction-item:hover {
  transform: scale(1.05);
  transition: transform 0.3s ease;
}

.attraction-item {
  width: 23%;
  margin-left: 2%;
  height: 300px;
  margin-top: 30px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end; /* Align content to the bottom */
  cursor: pointer;
  background-size: cover;
  background-position: center;
  border-radius: 50%;
}

.attraction-title {
  //background-color: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 20px;
  font-weight: bold;
  text-align: center;
  padding-top: 5px;
  padding-bottom: 30px;
  overflow: hidden;
}

.copyright {
  color: #002B49;
  font-size: 12px;
  padding: 20px;
  font-family: 'Microsoft YaHei', sans-serif;
}
</style>